package com.yourname.custom;

import com.yourname.entity.StudentScore;

import java.util.ArrayList;

public class CustomScoreStudentList extends ArrayList<StudentScore> {
    @Override
    public boolean contains(Object o) {
        StudentScore s=(StudentScore) o;
        for (StudentScore studentScore:this){
            if (studentScore.getId().equals(s.getId())){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean add(StudentScore teacher) {
        if (contains(teacher)){
            System.out.printf("教师%s已存在",teacher.getId());
            return false;
        }else{
            return super.add(teacher);
        }
    }
    public StudentScore get(String sid) {
        for (StudentScore StudentScore:this){
            if (StudentScore.getId().equals(sid)){
                return StudentScore;
            }
        }
        return null;
    }
    public boolean update(String sid,StudentScore newTeacher) {
        for (int i=0;i<this.size();i++){
            if (this.get(i).getId().equals(sid)){
                this.set(i,newTeacher);
                return true;
            }
        }
        return false;
    }

    public StudentScore remove(String sid) {
        for (int i=0;i<this.size();i++){
            if (this.get(i).getId().equals(sid)){
                return this.remove(i);
            }
        }
        return null;
    }
    public StudentScore set(StudentScore newSS){
        StudentScore ori=null;
        for (int i=0;i<this.size();i++){
            StudentScore target=this.get(i);
            ori=target;
            if (this.get(i).getId().equals(newSS.getId())){
                return this.set(i,newSS);
            }
        }
        return ori;
    }
}
